package com.example.helloandroid01;

import android.R.string;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity implements OnClickListener {

	int i = 0;
	int tempi = 0;
	int tempj = 0;
	String str;
	TextView showTextView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		showTextView = (TextView) findViewById(R.id.text);

		Button btn1 = (Button) findViewById(R.id.o);
		Button btn2 = (Button) findViewById(R.id.oo);
		Button btn3 = (Button) findViewById(R.id.ooo);
		Button btn4 = (Button) findViewById(R.id.oooo);
		Button btn5 = (Button) findViewById(R.id.ooooo);
		Button btn6 = (Button) findViewById(R.id.x);
		Button btn7 = (Button) findViewById(R.id.xx);
		Button btn8 = (Button) findViewById(R.id.xxx);
		Button btn9 = (Button) findViewById(R.id.xxxx);
		Button btn10 = (Button) findViewById(R.id.xxxxx);
		Button btn11 = (Button) findViewById(R.id.equals);
		Button btn12 = (Button) findViewById(R.id.plus);
		Button btn13 = (Button) findViewById(R.id.clear);

		btn1.setOnClickListener(this);
		btn2.setOnClickListener(this);
		btn3.setOnClickListener(this);
		btn4.setOnClickListener(this);
		btn5.setOnClickListener(this);
		btn6.setOnClickListener(this);
		btn7.setOnClickListener(this);
		btn8.setOnClickListener(this);
		btn9.setOnClickListener(this);
		btn10.setOnClickListener(this);
		btn11.setOnClickListener(this);
		btn12.setOnClickListener(this);
		btn13.setOnClickListener(this);

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.o:
			showTextView.append("1");
			break;

		case R.id.oo:
			showTextView.append("2");
			break;

		case R.id.ooo:
			showTextView.append("3");

			break;

		case R.id.oooo:
			showTextView.append("4");

			break;
		case R.id.ooooo:
			showTextView.append("5");

			break;
		case R.id.x:
			showTextView.append("6");

			break;
		case R.id.xx:
			showTextView.append("7");

			break;
		case R.id.xxx:
			showTextView.append("8");

			break;

		case R.id.xxxx:
			showTextView.append("9");

			break;
		case R.id.xxxxx:
			showTextView.append("0");

			break;
		case R.id.equals:
			tempi = Integer.parseInt((showTextView.getText()).toString());
			tempj += tempi;
			str = tempj + "";
			
			showTextView.setText(str);
			break;
		case R.id.plus:
			tempi = Integer.parseInt((showTextView.getText()).toString());
			tempj += tempi;
			Log.d("test1", "" + tempi);
			Log.d("test1", "" + tempj);
			showTextView.setText("");
			break;
		case R.id.clear:
			tempj = 0;
			tempj = 0;
			showTextView.setText("");

		}
	}
}
